var s = "   fly me   to   the moon  "
// var s = 'a'
var lengthOfLastWord = function (s) {
    let n = s.length;
    let i = n - 1;
    let count = 0;
    while (i >= 0) {
        if (s[i] !== ' ') {
            ++count;
        } else if (s[i] === ' ' && count) {
            return count;
        }
        --i;
    }
    return count;
};
console.log(lengthOfLastWord(s));
